package es.manuel.maa.applet;

interface AppletParamConverter<E> {

	E convert(String value);

	public static final AppletParamConverter<String> STRING_CONVERTER = new AppletParamConverter<String>() {
		public String convert(String value) {
			if (value == null)
				return null;
			return value;
		}
	};

	public static final AppletParamConverter<Integer> INTEGER_CONVERTER = new AppletParamConverter<Integer>() {
		public Integer convert(String value) {
			if (value == null)
				return null;
			return Integer.parseInt(value, 16);
		}
	};

	public static final AppletParamConverter<Long> LONG_CONVERTER = new AppletParamConverter<Long>() {
		public Long convert(String value) {
			if (value == null)
				return null;
			return Long.parseLong(value, 16);
		}
	};

	public static final AppletParamConverter<Double> DOUBLE_CONVERTER = new AppletParamConverter<Double>() {
		public Double convert(String value) {
			if (value == null)
				return null;
			return Double.parseDouble(value);
		}
	};

	public static final AppletParamConverter<Float> FLOAT_CONVERTER = new AppletParamConverter<Float>() {
		public Float convert(String value) {
			if (value == null)
				return null;
			return Float.parseFloat(value);
		}
	};

	public static final AppletParamConverter<Boolean> BOOLEAN_CONVERTER = new AppletParamConverter<Boolean>() {
		public Boolean convert(String value) {
			if (value == null)
				return null;
			return Boolean.parseBoolean(value);
		}
	};

	public static final AppletParamConverter<Short> SHORT_CONVERTER = new AppletParamConverter<Short>() {
		public Short convert(String value) {
			if (value == null)
				return null;
			return Short.parseShort(value);
		}
	};

}